<template>
  <gui-page class="gui-bg-white">
    <template v-slot:gBody>
      <view class="gui-bg-white gui-dark-bg-level-3 gui-padding">
        <view
          class="gui-list-items gui-border-b"
          style="padding: 15rpx"
          @tap="goDetail(item)"
          v-for="(item, index) in dataList"
          :key="item.noteId || index"
        >
          <view class="gui-list-image gui-relative">
            <image
              @tap.stop.prevent="goCard(item.followId)"
              style="width: 100rpx; height: 100rpx; border-radius: 100rpx"
              class="gui-list-image"
              mode="aspectFill"
              :src="item.avatarUrl"
            ></image>
          </view>
          <view class="gui-list-body" style="margin-left: 40rpx">
            <view class="gui-list-title">
              <text class="gui-list-title-text gui-primary-text">{{
                item.followName
              }}</text>
            </view>
            <text class="gui-list-body-desc gui-color-gray"
              >{{ item.type == "1" ? "赞" : "" }}了你的笔记 &nbsp;{{
                formatDate(item.createTime)
              }}</text
            >
          </view>
          <view>
            <image
              class="gui-border-radius"
              style="width: 80rpx; height: 75rpx; margin-top: 20rpx"
              :src="item.firstPicture"
              mode="aspectFill"
            ></image>
          </view>
        </view>

        <gui-empty v-show="dataList.length == 0" style="height: 600rpx">
          <template v-slot:img>
            <view class="gui-flex gui-rows gui-justify-content-center">
              <text
                class="gui-icons gui-empty-icon gui-color-gray"
                style="font-size: 80rpx"
                >&#xe6ad;
              </text>
            </view>
          </template>
          <template v-slot:text>
            <text
              class="gui-block gui-text-center xhs-margin-top-30 gui-color-gray"
              >暂无消息，多发消息可以收获赞和收藏~</text
            >
          </template>
        </gui-empty>

        <gui-loadmore
          v-show="dataList.length > 0"
          :loadMoreText="[
            '上划加载更多',
            '更多数据加载中',
            '已加载全部数据',
            '暂无数据',
          ]"
          ref="loadmorecom1"
          :status="1"
        ></gui-loadmore>
      </view>
    </template>
  </gui-page>
</template>
<script>
import commonMixin from "@/mixin/commonMinxin";

export default {
  mixins: [commonMixin],
  data() {
    return {
      dataList: [],
      page: 1,
      userId: uni.getStorageSync("userId"),
    };
  },
  onLoad(e) {
    console.log(e);
    this.getUpMeNotes();
  },
  onReachBottom: function () {
    console.log("到底了");
    var status = this.$refs["loadmorecom1"].loadMoreStatus;
    if (status == 2) return;
    this.getUpMeNotes();
  },
  onPullDownRefresh: function () {
    console.log("下拉刷新了");
    this.page = 1;
    this.getUpMeNotes(1);
  },
  methods: {
    goCard(authorId) {
      return uni.app.goCard(authorId);
    },
    //格式化时间
    formatDate(date) {
      return uni.app.formatDate(date);
    },
    //进入详情
    goDetail(e) {
      uni.navigateTo({
        url: "/pages/notes/detail/detail?noteId=" + e.noteId,
      });
    },
    getUpMeNotes(isReload) {
      uni.app.post(
        "/blog/note/getUpMeNotes",
        { limit: 10, offset: this.page, authorId: this.userId },
        "json",
        "",
        (res) => {
          console.log("接口返回数据:", res);
          console.log("records数据:", res.data.records);
          if (this.page <= res.data.pages) {
            if (this.page == 1) {
              this.dataList = res.data.records;
            } else {
              this.dataList = [...this.dataList, ...res.data.records];
            }
            console.log("赋值后的dataList:", this.dataList);

            if (this.page == res.data.pages) {
              //停止加载更多
              this.$refs.loadmorecom1.nomore();
            } else {
              this.page++;
              this.$refs.loadmorecom1.stoploadmore();
            }
          } else if (res.data.pages == 0) {
            this.$refs.loadmorecom1.nomore();
          }
        },
      );

      if (isReload) {
        uni.stopPullDownRefresh();
      }
    },
  },
};
</script>
<style scoped></style>
